<?php

namespace App\Http\Controllers;

use App\Models\AddressModel;
use Illuminate\Http\Request;

class AddressController extends Controller
{
    //市级
    public function province()
    {
        $class=new AddressModel();
        $addressDate=$class->where('pid',0)->select('id','name')->get()->toarray();
        foreach ($addressDate as $k=>$v){
            $province[$k]['id']=$v['id'];
            $province[$k]['text']=$v['name'];
        }

        return $province;
    }

    //根据pid查找子级
    public function city(Request $request)
    {
        $pid=$request->get('q');
        $class= new AddressModel();
        $addressDate=$class->where('pid',$pid)->select('id','name')->get()->toarray();
        foreach ($addressDate as $k=>$v){
            $city[$k]['id']=$v['id'];
            $city[$k]['text']=$v['name'];
        }
        return $city;
    }
}
